﻿namespace YiSha.Business.AutoJob;

public class DatabasesBackupJob : IJobTask
{
    private readonly DatabaseTableBLL _databaseTable;
    public DatabasesBackupJob(DatabaseTableBLL databaseTable)
    {
        _databaseTable = databaseTable;
    }
    public async Task<TData> Start()
    {
        TData obj = new TData();
        string backupPath = GlobalContext.SystemConfig.DBBackup;
        if (string.IsNullOrEmpty(backupPath))
        {
            backupPath = Path.Combine(GlobalContext.HostingEnvironment.ContentRootPath, "Database");
        }
        else
        {
            backupPath = Path.Combine(GlobalContext.HostingEnvironment.ContentRootPath, backupPath);
        }

        if (!Directory.Exists(backupPath))
        {
            Directory.CreateDirectory(backupPath);
        }

        string info =await _databaseTable.DatabaseBackup(backupPath);

        obj.Tag = 1;
        obj.Message = "备份路径：" + info;
        return obj;
    }
}